package BookStore.view;

import BookStore.dao.VipDao;
import BookStore.model.Vip;
import java.awt.EventQueue;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout.Alignment;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.LayoutStyle.ComponentPlacement;

public class add_vip extends JFrame {

    private JPanel contentPane;

    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;
    private JTextField textField_3;
    private JTextField textField_4;
    private JTextField textField_5;


    /**
     * Launch the application.
     */
    public static void xe () {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    add_vip frame = new add_vip();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public add_vip() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);

        JLabel lblNewLabel = new JLabel("添加用户");
        lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 25));
        lblNewLabel.setForeground(Color.RED);

        JLabel lblNewLabel_1 = new JLabel("请输入下列信息：");
        lblNewLabel_1.setForeground(Color.RED);

        JLabel lblNewLabel_2 = new JLabel("编号：");

        JLabel lblNewLabel_4 = new JLabel("姓名：");

        JLabel lblNewLabel_3 = new JLabel("性别：");

        JLabel lblNewLabel_5 = new JLabel("联系方式：");

        JLabel lblNewLabel_6 = new JLabel("等级：");

        JLabel lblNewLabel_7 = new JLabel("享受折扣：");

        JButton btnNewButton = new JButton("确认添加");

        textField = new JTextField();
        textField.setColumns(10);

        textField_1 = new JTextField();
        textField_1.setColumns(10);

        textField_2 = new JTextField();
        textField_2.setColumns(10);

        textField_3 = new JTextField();
        textField_3.setColumns(10);

        textField_4 = new JTextField();
        textField_4.setColumns(10);

        textField_5 = new JTextField();
        textField_5.setColumns(10);
        GroupLayout gl_contentPane = new GroupLayout(contentPane);
        gl_contentPane.setHorizontalGroup(
                gl_contentPane.createParallelGroup(Alignment.LEADING)
                        .addGroup(gl_contentPane.createSequentialGroup()
                                .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
                                        .addGroup(gl_contentPane.createSequentialGroup()
                                                .addGap(31)
                                                .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
                                                        .addGroup(gl_contentPane.createSequentialGroup()
                                                                .addPreferredGap(ComponentPlacement.RELATED)
                                                                .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
                                                                        .addComponent(lblNewLabel_5, Alignment.TRAILING)
                                                                        .addComponent(lblNewLabel_3, Alignment.TRAILING)
                                                                        .addComponent(lblNewLabel_4, Alignment.TRAILING)
                                                                        .addComponent(lblNewLabel_2, Alignment.TRAILING)
                                                                        .addComponent(lblNewLabel_6, Alignment.TRAILING)
                                                                        .addComponent(lblNewLabel_7, Alignment.TRAILING))
                                                                .addGap(18)
                                                                .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
                                                                        .addComponent(textField_5)
                                                                        .addComponent(textField_4)
                                                                        .addComponent(textField_3)
                                                                        .addComponent(textField_2)
                                                                        .addComponent(textField_1)
                                                                        .addComponent(textField, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE)))
                                                        .addGroup(gl_contentPane.createSequentialGroup()
                                                                .addComponent(lblNewLabel_1)
                                                                .addGap(26)
                                                                .addComponent(lblNewLabel))))
                                        .addGroup(gl_contentPane.createSequentialGroup()
                                                .addGap(160)
                                                .addComponent(btnNewButton)))
                                .addContainerGap(115, Short.MAX_VALUE))
        );
        gl_contentPane.setVerticalGroup(
                gl_contentPane.createParallelGroup(Alignment.LEADING)
                        .addGroup(gl_contentPane.createSequentialGroup()
                                .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
                                        .addGroup(gl_contentPane.createSequentialGroup()
                                                .addGap(22)
                                                .addComponent(lblNewLabel_1))
                                        .addComponent(lblNewLabel))
                                .addPreferredGap(ComponentPlacement.UNRELATED)
                                .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
                                        .addComponent(lblNewLabel_2)
                                        .addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(ComponentPlacement.RELATED)
                                .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
                                        .addComponent(lblNewLabel_4)
                                        .addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(ComponentPlacement.RELATED)
                                .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
                                        .addComponent(lblNewLabel_3)
                                        .addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(ComponentPlacement.RELATED)
                                .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
                                        .addComponent(lblNewLabel_5)
                                        .addComponent(textField_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(ComponentPlacement.RELATED)
                                .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
                                        .addComponent(lblNewLabel_6)
                                        .addComponent(textField_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(ComponentPlacement.RELATED)
                                .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
                                        .addComponent(lblNewLabel_7)
                                        .addComponent(textField_5, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(ComponentPlacement.UNRELATED)
                                .addComponent(btnNewButton)
                                .addContainerGap(15, Short.MAX_VALUE))
        );
        contentPane.setLayout(gl_contentPane);

        btnNewButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String t1 = textField.getText();
                String t2 = textField_1.getText();
                String t3 = textField_2.getText();
                String t4 = textField_3.getText();
                String t5 = textField_4.getText();
                String t6 = textField_5.getText();
                System.out.println(t1+t2+t3+t4+t5+t6);

                if (t1.length()>0&&t2.length()>0&&t3.length()>0&&t4.length()>0&&t5.length()>0&&t6.length()>0){

                    Vip vip = new Vip(t1,t2,t3,t4,t5,t6);

                    try {
                        new VipDao(vip).register_2();
                    }catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }else {
                    JOptionPane.showMessageDialog(null, "用户信息不能为空缺");
                }
            }
        });
    }
}
